/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.springapplication.adapters.impl;

import cz.muni.fi.pa165.springapplication.adapters.CustomerAdapter;
import cz.muni.fi.pa165.springapplication.dto.CustomerDTO;
import cz.muni.fi.pa165.springapplication.entities.Customer;
import cz.muni.fi.pa165.springapplication.exceptions.IllegalOrphanException;
import cz.muni.fi.pa165.springapplication.exceptions.NonexistentEntityException;
import cz.muni.fi.pa165.springapplication.exceptions.PreexistingEntityException;
import cz.muni.fi.pa165.springapplication.services.CustomerService;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Daniel Sák, 374560
 */
public class CustomerAdapterImpl implements CustomerAdapter{
    @Autowired
    private CustomerService customerService;
    
    @Override
    public void createCustomer(CustomerDTO customer) throws IllegalOrphanException, PreexistingEntityException{       
        Customer customerEntity = AdaptersHelper.customerDTOToEntity(customer);
        customerService.createCustomer(customerEntity);
    }

    @Override
    public void updateCustomer(CustomerDTO customer) throws NonexistentEntityException, IllegalOrphanException, PreexistingEntityException, Exception {
        Customer customerEntity = AdaptersHelper.customerDTOToEntity(customer);
        customerService.updateCustomer(customerEntity);
    }

    @Override
    public void deleteCustomer(CustomerDTO customer) throws NonexistentEntityException, IllegalOrphanException {
        Customer customerEntity = AdaptersHelper.customerDTOToEntity(customer);
        customerService.deleteCustomer(customerEntity);
    }

    @Override
    public CustomerDTO getCustomerById(Long customerId) {
        Customer customerEntity = customerService.getCustomerById(customerId);
        CustomerDTO customer = AdaptersHelper.customerEntityToDTO(customerEntity);
        return customer;
    }

    
    
    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }

    
}
    

